

tactile.logger.setLevel(tactile.logger.level.warn);
var page = tactile.page;
var demo =  {
    init: function() {
        //menu click
        tactile.EventManager.addListener("news-navigation", "click", demo.newsClicked);
    	tactile.EventManager.addListener("video-navigation", "click", demo.videoClicked);
        
        //video swipe
        tactile.EventManager.addListener("multiview-video", "swipe", demo.multiviewVideoSwipe);
        
        
        //default page
        demo.newsClicked();
    },
    newsClicked: function(e) {        
        var news = page.getComponent("news-navigation");
        news.addClass("selected");
        
        var video = page.getComponent("video-navigation");
        video.removeClass("selected");
        
        var multiviewNews = page.getComponent("multiview-news");
        var multiviewVideo = page.getComponent("multiview-video");

        multiviewNews.show(); 
        multiviewVideo.hide();        
        
    },
    videoClicked: function(e) {
        var news = page.getComponent("news-navigation");
        news.removeClass("selected");
        
        var video = page.getComponent("video-navigation");
        video.addClass("selected");
        
        var multiviewNews = page.getComponent("multiview-news");
        var multiviewVideo = page.getComponent("multiview-video");

        multiviewNews.hide(); 
        multiviewVideo.show();        
        
    },
    multiviewVideoSwipe: function(e) {
        var multiviewVideo = page.getComponent("multiview-video");
        var direction = e.direction.toUpperCase();
        if (direction=="LEFT") {
            multiviewVideo.showPrev({
                slideto: tactile.Enum.Direction.west,
                slidefrom: tactile.Enum.Direction.east
            });
        }else if (direction=="RIGHT") {
            multiviewVideo.showNext({
                slideto: tactile.Enum.Direction.east,
                slidefrom: tactile.Enum.Direction.west
            });
        }
    }
    
};

page.onready(demo.init);